package com.web.cms.doc.util;

import com.blue.jdbc.Page;
import com.web.cms.doc.message.DocCommentRequest;
import com.web.cms.doc.message.DocCommentResponse;
import com.web.cms.doc.model.DocComment;

import java.util.ArrayList;
import java.util.List;

public class DocCommentConvertor
{
	private DocCommentConvertor()
	{
	}
	
	public static DocComment toDocComment(DocCommentRequest request)
	{
		if (request == null)
			return null;
		
		DocComment comment = new DocComment();
		comment.setId(request.getId());
		comment.setDocId(request.getDocId());
		comment.setUserId(request.getUserId());
		comment.setAuthor(request.getAuthor());
		comment.setContent(request.getContent());
		comment.setCreateTime(request.getCreateTime());
		return comment;
	}
	
	public static DocCommentResponse toResponse(DocComment comment)
	{
		if (comment == null)
			return null;
		
		DocCommentResponse response = new DocCommentResponse();
		response.setId(comment.getId());
		response.setDocId(comment.getDocId());
		response.setUserId(comment.getUserId());
		response.setAuthor(comment.getAuthor());
		response.setContent(comment.getContent());
		response.setCreateTime(comment.getCreateTime());
		return response;
	}
	
	public static List<DocCommentResponse> toResponse(List<DocComment> list)
	{
		List<DocCommentResponse> responseList = new ArrayList<>();
		if (list == null || list.isEmpty())
			return responseList;
		
		for (DocComment comment : list)
		{
			responseList.add(toResponse(comment));
		}
		return responseList;
	}
	
	public static Page<DocCommentResponse> toResponse(Page<DocComment> page)
	{
		Page<DocCommentResponse> pageResponse = new Page<>();
		pageResponse.setCurPage(page.getCurPage());
		pageResponse.setRows(page.getRows());
		pageResponse.setSize(page.getSize());
		pageResponse.setStartRowNo(page.getStartRowNo());
		pageResponse.setTotalPage(page.getTotalPage());
		pageResponse.setObjectList(toResponse(page.getObjectList()));
		return pageResponse;
	}
	
}
